package com.estate.quarters.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.estate.bean.Quarters;
import com.estate.mapper.QuartersMapper;
import com.estate.quarters.service.QuartersService;
import com.estate.util.JsonResult;
import com.estate.util.ResultTool;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class QuartersServiceImpl extends ServiceImpl<QuartersMapper, Quarters> implements QuartersService {

    @Override
    public JsonResult findById(String id) {
        Quarters quarters = this.getById(id);
        return ResultTool.success(quarters);
    }

    @Override
    public JsonResult listByPage(int page, int size) {
        PageHelper.startPage(page, size);
        List<Quarters> list = this.list();
        PageInfo<Quarters> pageInfo = new PageInfo<>(list);
        return ResultTool.success(pageInfo);
    }

    @Override
    public JsonResult addQuarters(Quarters quarters) {
        boolean b = this.save(quarters);
        if (!b) {
            return ResultTool.fail(501, "添加失败");
        }
        return ResultTool.success("添加成功");
    }

    @Override
    public JsonResult updateQuarters(Quarters quarters) {
        boolean b = this.updateById(quarters);
        if (!b) {
            return ResultTool.fail(503, "修改失败");
        }
        return ResultTool.success("修改成功");
    }

    @Override
    public JsonResult deleteQuarters(String id) {
        boolean b = this.removeById(id);
        if (!b) {
            return ResultTool.fail(502, "删除失败");
        }
        return ResultTool.success("删除成功");
    }

}
